package com.financing.wap.common;

import java.util.HashMap;
import java.util.Map;

import com.financing.wap.dto.DstUserInfoDTO;

public class SessionImpl implements Session {
	
	private boolean login = false;
	
	private DstUserInfoDTO user;
	
	private Map<String, Object> attributes = new HashMap<String, Object>();

	public boolean getLogin() {
		return login;
	}

	public void setLogin(boolean login) {
		this.login = login;
	}
	
	@Override
	public DstUserInfoDTO getUser() {
		return user;
	}

	@Override
	public void setUser(DstUserInfoDTO user) {
		this.user=user;
	}
	
	public void setAttribute(String key, Object value) {
		attributes.put(key, value);
		
	}

	public Object getAttribute(String key) {
		
		return attributes.get(key);
		
	}
	
	public static class EmptySession implements Session {
		

		@Override
		public boolean getLogin() {
			return false;
		}

		@Override
		public void setLogin(boolean login) {
			throw new IllegalStateException("cannot modify state");
		}

		@Override
		public DstUserInfoDTO getUser() {
			return null;
		}

		@Override
		public void setUser(DstUserInfoDTO user) {
			throw new IllegalStateException("cannot modify state");
		}

		@Override
		public void setAttribute(String key, Object value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public Object getAttribute(String key) {
			return null;
			
		}
		
	}

}
